﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmTsctgs.
	/// </summary>
	public class frmTsctgs : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label42;
		private System.Windows.Forms.Label label50;
		private System.Windows.Forms.Label label37;
		private System.Windows.Forms.Label label34;
		private System.Windows.Forms.ComboBox chucnang;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.NumericUpDown mm;
		private System.Windows.Forms.NumericUpDown yyyy;
		private System.Windows.Forms.Button butChon;
		private System.Windows.Forms.Button butExit;
		private System.Windows.Forms.ComboBox nhom;
		private System.Windows.Forms.ComboBox lk;
		private System.Windows.Forms.ComboBox chuong;
		private System.Windows.Forms.ComboBox lctug;
		private int userid;
		public string mmyy;
		private AccessData a;
		public int iNhom,iChucnang,iLctug,iChuong,iLk;
		private bool bClear=true;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmTsctgs(AccessData acc,string _mmyy,int _userid)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;mmyy=_mmyy;userid=_userid;
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmTsctgs));
            this.nhom = new System.Windows.Forms.ComboBox();
            this.label42 = new System.Windows.Forms.Label();
            this.lk = new System.Windows.Forms.ComboBox();
            this.label50 = new System.Windows.Forms.Label();
            this.chuong = new System.Windows.Forms.ComboBox();
            this.label37 = new System.Windows.Forms.Label();
            this.lctug = new System.Windows.Forms.ComboBox();
            this.label34 = new System.Windows.Forms.Label();
            this.chucnang = new System.Windows.Forms.ComboBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.mm = new System.Windows.Forms.NumericUpDown();
            this.yyyy = new System.Windows.Forms.NumericUpDown();
            this.butChon = new System.Windows.Forms.Button();
            this.butExit = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.mm)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.yyyy)).BeginInit();
            this.SuspendLayout();
            // 
            // nhom
            // 
            this.nhom.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.nhom.BackColor = System.Drawing.SystemColors.HighlightText;
            this.nhom.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.nhom.Location = new System.Drawing.Point(64, 10);
            this.nhom.Name = "nhom";
            this.nhom.Size = new System.Drawing.Size(200, 21);
            this.nhom.TabIndex = 1;
            this.nhom.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nhom_KeyDown);
            // 
            // label42
            // 
            this.label42.Location = new System.Drawing.Point(0, 10);
            this.label42.Name = "label42";
            this.label42.Size = new System.Drawing.Size(64, 23);
            this.label42.TabIndex = 0;
            this.label42.Text = "Nhóm :";
            this.label42.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lk
            // 
            this.lk.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lk.BackColor = System.Drawing.SystemColors.HighlightText;
            this.lk.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lk.Location = new System.Drawing.Point(64, 102);
            this.lk.Name = "lk";
            this.lk.Size = new System.Drawing.Size(200, 21);
            this.lk.TabIndex = 9;
            this.lk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nhom_KeyDown);
            // 
            // label50
            // 
            this.label50.Location = new System.Drawing.Point(-8, 101);
            this.label50.Name = "label50";
            this.label50.Size = new System.Drawing.Size(72, 23);
            this.label50.TabIndex = 8;
            this.label50.Text = "Loại khoản :";
            this.label50.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // chuong
            // 
            this.chuong.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.chuong.BackColor = System.Drawing.SystemColors.HighlightText;
            this.chuong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.chuong.Location = new System.Drawing.Point(64, 79);
            this.chuong.Name = "chuong";
            this.chuong.Size = new System.Drawing.Size(200, 21);
            this.chuong.TabIndex = 7;
            this.chuong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nhom_KeyDown);
            // 
            // label37
            // 
            this.label37.Location = new System.Drawing.Point(8, 77);
            this.label37.Name = "label37";
            this.label37.Size = new System.Drawing.Size(56, 23);
            this.label37.TabIndex = 6;
            this.label37.Text = "Chương :";
            this.label37.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lctug
            // 
            this.lctug.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lctug.BackColor = System.Drawing.SystemColors.HighlightText;
            this.lctug.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lctug.Location = new System.Drawing.Point(64, 56);
            this.lctug.Name = "lctug";
            this.lctug.Size = new System.Drawing.Size(200, 21);
            this.lctug.TabIndex = 5;
            this.lctug.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nhom_KeyDown);
            // 
            // label34
            // 
            this.label34.Location = new System.Drawing.Point(16, 56);
            this.label34.Name = "label34";
            this.label34.Size = new System.Drawing.Size(48, 23);
            this.label34.TabIndex = 4;
            this.label34.Text = "Loại :";
            this.label34.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // chucnang
            // 
            this.chucnang.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.chucnang.BackColor = System.Drawing.SystemColors.HighlightText;
            this.chucnang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.chucnang.Location = new System.Drawing.Point(64, 33);
            this.chucnang.Name = "chucnang";
            this.chucnang.Size = new System.Drawing.Size(200, 21);
            this.chucnang.TabIndex = 3;
            this.chucnang.SelectedIndexChanged += new System.EventHandler(this.chucnang_SelectedIndexChanged);
            this.chucnang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nhom_KeyDown);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(-8, 31);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(72, 23);
            this.label1.TabIndex = 2;
            this.label1.Text = "Chức năng :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(-8, 126);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(72, 23);
            this.label2.TabIndex = 10;
            this.label2.Text = "Tháng :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(160, 126);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(48, 23);
            this.label3.TabIndex = 12;
            this.label3.Text = "Năm :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // mm
            // 
            this.mm.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.mm.Location = new System.Drawing.Point(64, 126);
            this.mm.Maximum = new decimal(new int[] {
            12,
            0,
            0,
            0});
            this.mm.Minimum = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.mm.Name = "mm";
            this.mm.Size = new System.Drawing.Size(56, 21);
            this.mm.TabIndex = 11;
            this.mm.Value = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.mm.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nhom_KeyDown);
            // 
            // yyyy
            // 
            this.yyyy.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.yyyy.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.yyyy.Location = new System.Drawing.Point(208, 126);
            this.yyyy.Maximum = new decimal(new int[] {
            3000,
            0,
            0,
            0});
            this.yyyy.Minimum = new decimal(new int[] {
            2000,
            0,
            0,
            0});
            this.yyyy.Name = "yyyy";
            this.yyyy.Size = new System.Drawing.Size(56, 21);
            this.yyyy.TabIndex = 13;
            this.yyyy.Value = new decimal(new int[] {
            2000,
            0,
            0,
            0});
            this.yyyy.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nhom_KeyDown);
            // 
            // butChon
            // 
            this.butChon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butChon.Image = ((System.Drawing.Image)(resources.GetObject("butChon.Image")));
            this.butChon.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butChon.Location = new System.Drawing.Point(64, 152);
            this.butChon.Name = "butChon";
            this.butChon.Size = new System.Drawing.Size(68, 25);
            this.butChon.TabIndex = 14;
            this.butChon.Text = "    Chọn";
            this.butChon.Click += new System.EventHandler(this.butChon_Click);
            // 
            // butExit
            // 
            this.butExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butExit.Image = ((System.Drawing.Image)(resources.GetObject("butExit.Image")));
            this.butExit.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butExit.Location = new System.Drawing.Point(134, 152);
            this.butExit.Name = "butExit";
            this.butExit.Size = new System.Drawing.Size(68, 25);
            this.butExit.TabIndex = 15;
            this.butExit.Text = "Kết thúc";
            this.butExit.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butExit.Click += new System.EventHandler(this.butExit_Click);
            // 
            // frmTsctgs
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(272, 189);
            this.Controls.Add(this.butExit);
            this.Controls.Add(this.butChon);
            this.Controls.Add(this.yyyy);
            this.Controls.Add(this.mm);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.chucnang);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.nhom);
            this.Controls.Add(this.label42);
            this.Controls.Add(this.lk);
            this.Controls.Add(this.label50);
            this.Controls.Add(this.chuong);
            this.Controls.Add(this.label37);
            this.Controls.Add(this.lctug);
            this.Controls.Add(this.label34);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmTsctgs";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Chứng từ ghi sổ";
            this.Load += new System.EventHandler(this.frmTsctgs_Load);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmTsctgs_MouseMove);
            ((System.ComponentModel.ISupportInitialize)(this.mm)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.yyyy)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		private void frmTsctgs_Load(object sender, System.EventArgs e)
		{		
			mm.Value=decimal.Parse(mmyy.Substring(0,2));
			yyyy.Value=decimal.Parse("20"+mmyy.Substring(2));

			chuong.DisplayMember="TEN";
			chuong.ValueMember="ID";
			chuong.DataSource=a.get_data("select * from a_dmchuong where sudung=1 order by stt").Tables[0];
          
			lk.DisplayMember="LK";
			lk.ValueMember="ID";
			lk.DataSource=a.get_data("select id,lk||' '||tlk as lk,tlk from a_dmlk order by stt").Tables[0];

			nhom.DisplayMember="TEN";
			nhom.ValueMember="ID";
			nhom.DataSource=a.get_data("select * from a_dmnhombc order by stt").Tables[0];

			chucnang.DisplayMember="TEN";
			chucnang.ValueMember="ID";
			chucnang.DataSource=a.get_data("select * from a_dmchucnang where sudung=1 order by stt").Tables[0];

			lctug.DisplayMember="TEN";
			lctug.ValueMember="ID";
			load_lctug();
		}

		private void load_lctug()
		{
			if (chucnang.SelectedIndex!=-1)
			{
				lctug.DataSource=a.get_data("select * from a_bcnghang where chucnang="+int.Parse(chucnang.SelectedValue.ToString())+" order by stt").Tables[0];
				if (lctug.Items.Count>0) lctug.SelectedIndex=0;
				//lctug.SelectedIndex=-1;
			}
		}

		private void chucnang_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==chucnang && chucnang.SelectedIndex!=-1) load_lctug();
		}

		private bool kiemtra()
		{
			/*
			if (nhom.SelectedIndex==-1)
			{
				MessageBox.Show("Chọn nhóm !",a.Msg);
				nhom.Focus();
				return false;
			}
			if (chucnang.SelectedIndex==-1)
			{
				MessageBox.Show("Chọn chức năng !",a.Msg);
				chucnang.Focus();
				return false;
			}
			if (nhom.SelectedIndex==-1)
			{
				MessageBox.Show("Chọn chương !",a.Msg);
				chuong.Focus();
				return false;
			}
			if (lk.SelectedIndex==-1)
			{
				MessageBox.Show("Chọn loại khoản !",a.Msg);
				lk.Focus();
				return false;
			}*/
			return true;
		}
		private void butChon_Click(object sender, System.EventArgs e)
		{
			mmyy=mm.Value.ToString().PadLeft(2,'0')+yyyy.Value.ToString().Substring(2);
			iNhom=(nhom.SelectedIndex!=-1)?int.Parse(nhom.SelectedValue.ToString()):0;
			iChucnang=(chucnang.SelectedIndex!=-1)?int.Parse(chucnang.SelectedValue.ToString()):0;
			iLctug=(lctug.SelectedIndex!=-1)?int.Parse(lctug.SelectedValue.ToString()):0;
			iChuong=(chuong.SelectedIndex!=-1)?int.Parse(chuong.SelectedValue.ToString()):0;
			iLk=(lk.SelectedIndex!=-1)?int.Parse(lk.SelectedValue.ToString()):0;
			this.Close();
		}

		private void butExit_Click(object sender, System.EventArgs e)
		{
			mmyy="";
			this.Close();
		}

		private void frmTsctgs_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (bClear)
			{
				nhom.SelectedIndex=chucnang.SelectedIndex=lctug.SelectedIndex=chuong.SelectedIndex=lk.SelectedIndex=-1;
				bClear=false;
			}
		}

		private void nhom_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");
		}
	}
}
